package cn.fscode.code.generator.controller;

import cn.fscode.code.generator.model.req.GeneratorReq;
import cn.fscode.code.generator.model.resp.CodeFileResp;
import cn.fscode.code.generator.service.GeneratorService;
import cn.fscode.commons.core.response.Resp;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author shenguangyang
 */
@RestController
@RequestMapping("/api/gen")
@RequiredArgsConstructor
public class GeneratorController {
    private final GeneratorService generatorService;

    /**
     * 生成代码
     *
     * @param generatorReq 生成参数
     * @return 返回代码内容
     */
    @PostMapping("/code")
    public Resp<List<CodeFileResp>> genCode(@RequestBody @Validated GeneratorReq generatorReq) {
        return Resp.ok(generatorService.generate(generatorReq));
    }
}
